import { HTTP } from 'utils/http';
import config from 'utils/config';
/**
 * INSERT_PLAN_ITEM: BASE_URL + 'plan/insertPlanItem',
	DELETE_PLAN_ITEM: BASE_URL + 'plan/deletePlanItem',
	GET_PLAN_ITEM: BASE_URL + 'plan/getPlanItem',
	UPDATE_PLAN_ITEM: BASE_URL + 'plan/updatePlanItem',
	TOGGLE_COMPLETED_STATUS: BASE_URL + 'plan/toggleCompletedStatus'
 * */
// 添加计划事项
class InsertPlanItemModel extends HTTP{
    insertPlanItem(dataItem) {
        return new Promise((resolve, reject) => {
            this.axiosPost({
                url: config.API.INSERT_PLAN_ITEM,
                data: {
                    id: dataItem.id,
                    content: dataItem.content,
                    completed:dataItem.completed
                },
                success(data) {
                    resolve({
                        data,
                        status: 0
                    });
                },
                error(error) {
                    resolve({
                        error,
                        status: -1
                    })
                }
            });
        });
    }
}

// 删除计划事项
class DeletePlanItemModel extends HTTP{
    deletePlanItem(id) {
        return new Promise((resolve, reject) => {
            this.axiosPost({
                url: config.API.DELETE_PLAN_ITEM,
                data: {
                    id
                },
                success(data) {
                    resolve({
                        data,
                        status: 0
                    });
                },
                error(error) {
                    resolve({
                        error,
                        status: -1
                    })
                }
            });
        });
    }
}

// 查询计划事项
class GetPlanItemModel extends HTTP{
    getPlanItem() {
        return new Promise((resolve, reject) => {
            this.axiosPost({
                url: config.API.GET_PLAN_ITEM,
                success(data) {
                    resolve({
                        data,
                        status: 0
                    });
                },
                error(error) {
                    resolve({
                        error,
                        status: -1
                    })
                }
            });
        });
    }
}

// 更新计划事项
class UpdatePlanItemModel extends HTTP{
    updatePlanItem(dataItem,oldId) {
        return new Promise((resolve, reject) => {
            this.axiosPost({
                url: config.API.UPDATE_PLAN_ITEM,
                data: {
                    id: dataItem.id,
                    content: dataItem.content,
                    completed: dataItem.completed,
                    oldId
                },
                success(data) {
                    resolve({
                        data,
                        status: 0
                    });
                },
                error(error) {
                    resolve({
                        error,
                        status: -1
                    })
                }
            });
        });
    }
}

// 修改完成状态
class ToggleCompletedStatusModel extends HTTP{
    toggleCompletedStatus(id) {
        return new Promise((resolve, reject) => {
            this.axiosPost({
                url: config.API.TOGGLE_COMPLETED_STATUS,
                data: {
                    id
                },
                success(data) {
                    resolve({
                        data,
                        status: 0
                    });
                },
                error(error) {
                    resolve({
                        error,
                        status: -1
                    })
                }
            });
        });
    }
}

export {InsertPlanItemModel,DeletePlanItemModel,GetPlanItemModel,UpdatePlanItemModel,ToggleCompletedStatusModel}